 function DepState()
{
  this.reads = [];
  this.writes = [];
}
//DepState.prototype = new State();

function stackApplications(stack)
{
  var applications = [];
  for (var i = 0; i < stack.length; i++)
  {
    var elem = stack[i];
    if (elem instanceof Cont)
    {
      applications = applications.concat(elem.marks.map(function (mark) {return mark.application}));
    }
  }
  return applications;
}

DepState.prototype.readsAddress = 
  function (address, value, stack)
  {
    stackApplications(stack).forEach(
      function (application) 
      {
        this.reads = this.reads.updateSetEntry(application, address);        
      }, this);
    return this;
  };
    
DepState.prototype.writesAddress = 
  function (address, value, stack)
  {
    stackApplications(stack).forEach(
      function (application) 
      {
        this.writes = this.writes.updateSetEntry(application, address);
      }, this);
    return this;
  };
      
DepState.prototype.addressesRead =
  function (application)
  {
    return this.reads.getSetEntry(application);
  };

DepState.prototype.addressesWritten =
  function (application)
  {
    return this.writes.getSetEntry(application);
  };
      
      
DepState.prototype.varReadBy =
  function (vr)
  {
    return this.reads.flatMap(
      function (entry)
      {
        return entry[1].flatMap(
          function (varAddress)
          {
            return (varAddress.base === vr) ? [entry[0]] : [];
          });
      });
  };

DepState.prototype.varWrittenBy =
  function (vr)
  {
    return this.writes.flatMap(
      function (entry)
      {
        return entry[1].flatMap(
          function (varAddress)
          {
            return (varAddress.base === vr) ? [entry[0]] : [];
          });
      });
  };
      
DepState.prototype.readVars =
  function (node)
  {
    var vsthis = isCallExpression(node) ? this.addressesRead(node) : [];
    var cs = children(node).filter(function (n) { return !isFunctionExpression(n) });
    var vscs = cs.flatMap(this.readVars, this);
    return append(vsthis, vscs);
  };

DepState.prototype.writtenVars =
  function (node)
  {
    var vsthis = isCallExpression(node) ? this.addressesWritten(node) : [];
    var cs = children(node).filter(function (n) { return !isFunctionExpression(n) });
    var vscs = cs.flatMap(this.writtenVars, this);
    return append(vsthis, vscs);
  };

